﻿using System;
using System.Collections.Generic;

namespace _030泛型_部分类_枚举_结构体_3
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //多态
            //IDictionary<int, string> dict = new Dictionary<int, string>();
            //dict[1] = "lili";
            //dict[2] = "chengzi";
            //Console.WriteLine($"Student #1 is {dict[1]},Student #2 is {dict[2]}");


            //重载所带来的问题 成员膨胀
            int[] a1 = [1, 2, 3, 4, 5];
            int[] a2 = { 1, 2, 3, 4, 5 };
            var result1 = Zip(a1, a2);
            Console.WriteLine(string.Join(",",result1));

            double[] b1 = [1.1, 2.2, 3.3, 4.4, 5.5];
            double[] b2 = [1.1, 2.2, 3.3, 4.4, 5.5];
            var result2 = Zip(b1, b2);
            Console.WriteLine(string.Join(",", result2));
        }

        //要是double要重新写过方法
        static T[]Zip<T>(T[] a, T[] b)
        {
            T[] zipped = new T[a.Length + b.Length];
            int ai = 0, bi = 0, zi = 0;
            do
            {
                if (ai < a.Length) zipped[zi++] = a[ai++];
                if (bi < b.Length) zipped[zi++] = b[bi++];
            } while (ai < a.Length || bi < b.Length);

            return zipped;
        }
    }
}
